USE [TBbilling]
GO
/****** Object:  UserDefinedFunction [dbo].[getnextofKin]    Script Date: 02/06/2015 15:43:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>


--   select * from dbo.getnextofKin (4330)

-- drop function dbo.getnextofKin
-- =============================================
create FUNCTION [dbo].[getnextofKin]
(	
	-- Add the parameters for the function here
	@mpiid int)
RETURNS TABLE 
AS
RETURN 
(
	-- Add the SELECT statement with parameter references here
	select Top 1 c.MPIID
	, c.Person_Name
	, c.Relationship  
	,p.Home_Phone
	from Angus.dbo.shr_MPI_Contacts C
	left join Angus.dbo.glb_people P
	  on c.PeopleID = p.PeopleID
	
					where MPIID = @MPIID
					
					Order by C.MPIID
)
GO
